//
//  MWProgressView.m
//  SocietySale
//
//  Created by yumingwei on 2016/11/26.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MWProgressView.h"

@interface MWProgressView ()
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIView *circleView;
@end

@implementation MWProgressView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.frame = CGRectMake(0, 0, APPFRAME.size.width, 290);
        self.backgroundColor = [UIColor whiteColor];
        [self initUI];
    }
    return self;
}

- (void)initUI{
    UIView *normalView = [[UIView alloc] initWithFrame:CGRectMake(12, 5, SCREEN_WIDTH-24, 8)];
    normalView.backgroundColor = kNormalGray;
    normalView.layer.cornerRadius = 4;
    [self addSubview:normalView];
    
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(12, 5, SCREEN_WIDTH-24, 8)];
    self.bgView.layer.cornerRadius = 4;
    self.bgView.layer.masksToBounds = YES;
    [self addSubview:self.bgView];
    
    _circleView = [[UIView alloc] initWithFrame:CGRectMake(0, self.bgView.top-4, 16, 16)];
    _circleView.layer.cornerRadius = _circleView.width/2;
    _circleView.layer.borderWidth = 4;
    _circleView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_circleView];
}

- (void)setTitleArray:(NSArray *)titleArray{
    for (int i = 0; i<titleArray.count; i++) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(SCREEN_WIDTH/(titleArray.count-1)-35, self.bgView.bottom+10, 70, 20);
        label.tag = 10+i;
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = kDarkGrayColor;
        label.text = titleArray[i];
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        
        if (i == 0) {
            label.left = 12;
            label.textAlignment = NSTextAlignmentLeft;
        }
        if (i == titleArray.count-1) {
            label.textAlignment = NSTextAlignmentRight;
            label.left = SCREEN_WIDTH-82;
        }
    }
    CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
    gradientLayer.colors = @[(__bridge id)self.startColor.CGColor,(__bridge id)self.endColor.CGColor];
    //位置x,y    自己根据需求进行设置   使其从不同位置进行渐变
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1, 0);
    
    gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.bgView.frame), CGRectGetHeight(self.bgView.frame));
    [self.bgView.layer addSublayer:gradientLayer];
    
    _circleView.layer.borderColor = self.endColor.CGColor;
}

- (void)setSelectedIndex:(NSInteger)selectedIndex{
    UILabel *label = [self viewWithTag:selectedIndex+10];
    label.textColor = self.endColor;
    if (selectedIndex == 0) {
        self.bgView.width = 28;
        _circleView.left = 12+self.bgView.width-7;
    }
    if (selectedIndex == 1) {
        self.bgView.width = (SCREEN_WIDTH-24)/2;
        _circleView.left = 12+self.bgView.width-7;
    }
    if (selectedIndex == 2){
        self.bgView.width = SCREEN_WIDTH-24;
        _circleView.left = 12+self.bgView.width-30-7;
    }
}

@end
